import React from 'react';
import { BrowserRouter as Router, Redirect, Route, Switch } from 'react-router-dom'
import Contents from './views/Contents';
import 'antd/dist/antd.less';
import Login from './views/Login';

const PrivateRoute = ({component:Com,...rest}) => {
  return <Route {...rest} render={({location})=>{
      const userinfo = localStorage.getItem('username')
      if(userinfo) {
          return <Com />
      } else {
          return <Redirect to={{
              pathname: '/login',
              state: location.pathname
          }} />
      }
  }}/>
}


function App() {
  return (
    <Router>
      <Switch>
        <Route path='/login' component={Login} />
        <PrivateRoute path='/' component={Contents} />
      </Switch>
    </Router>
  );
}

export default App;

